/* $Id: MonitorEntry2.java 67 2010-10-11 10:26:34Z altdotua@gmail.com $ */

package alt.djudge.frontend.server.datatypes;

import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Vector;

public class MonitorEntry2 implements Serializable
{
	private static final long serialVersionUID = 1L;

	List<MonitorRowEntry> rows = new Vector<MonitorRowEntry>();
	
	List<ContestProblemEntry> problems = new Vector<ContestProblemEntry>();
	
	public static String getEntryCacheKey(String id)
	{
		return MonitorEntry2.class.getSimpleName() + "::class::" + id;
	}
	
	public void addRow(MonitorRowEntry rowEntry)
	{
		rows.add(rowEntry);
	}
	
	public void setProblems(List<ContestProblemEntry> problems)
	{
		this.problems = problems;
	}
	
	public List<ContestProblemEntry> getProblems()
	{
		return problems;
	}
	
	public List<MonitorRowEntry> getRows()
	{
		return rows;
	}
	
	public void sortIOI()
	{
		Collections.sort(rows);
	}
	
	public void sortACM()
	{
		Collections.sort(rows, new Comparator<MonitorRowEntry>()
				{
					@Override
					public int compare(MonitorRowEntry o1, MonitorRowEntry o2)
					{
						int k = o2.getSolved() - o1.getSolved();
						if (k == 0)
							return o1.getTime().compareTo(o2.getTime());
						return k;
					}
				});
	}
}
